<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('员工姓名')" prop="staffName">
            <UserSelect v-model="form.staffName" :placeholder="$t('员工姓名')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('所属部门')" prop="departmentId">
            <tree-select v-model="form.departmentId" node-key="id" disabled :default-expand-all="true" :data="deptOptions" :placeholder="$t('请选择')">
              <label slot="option-label" slot-scope="{ node, shouldShowCount, count, labelClassName, countClassName }" :class="labelClassName">
                {{ $t(node.label) }}
                <span v-if="shouldShowCount" :class="countClassName">({{ count }})</span>
              </label>
            </tree-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('现任职位')" prop="postId">
            <el-select v-model="form.postId" disabled>
              <el-option
                v-for="(item) in hrPositions"
                :key="item.id"
                :label="$t(item.postName)"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('身份证号码')" prop="idCard">
            <el-input v-model="form.idCard" :placeholder="$t('身份证号码')" show-word-limit maxlength="30" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('护照号码')" prop="passportNumber">
            <el-input v-model="form.passportNumber" :placeholder="$t('护照号码')" show-word-limit maxlength="30" />
          </el-form-item>
        </el-col>
      </el-row>
      <div style="margin-top: 15px">
        <!--关系密切家庭成员基本情况-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('关系密切家庭成员基本情况') }}</span>
        </div>
        <el-table :data="form.riskFamilyMembersList" border class="nowrapTable formTable">
          <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('姓名')" align="center" min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('姓名') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskFamilyMembersList.' + scope.$index + '.name'" :rules="riskFamilyMembersListRules.name">
                <el-input v-model="scope.row.name" :placeholder="$t('姓名')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('与本人关系')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('与本人关系') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskFamilyMembersList.' + scope.$index + '.relationship'" :rules="riskFamilyMembersListRules.relationship">
                <el-select v-model="scope.row.relationship">
                  <el-option
                    v-for="dict in relationshipOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('身份证号码')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('身份证号码') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskFamilyMembersList.' + scope.$index + '.idCard'" :rules="riskFamilyMembersListRules.idCard">
                <el-input v-model="scope.row.idCard" :placeholder="$t('身份证号码')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('护照号码')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('护照号码') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskFamilyMembersList.' + scope.$index + '.passportNumber'" :rules="riskFamilyMembersListRules.passportNumber">
                <el-input v-model="scope.row.passportNumber" :placeholder="$t('护照号码')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" width="60px">
            <template slot-scope="scope">
              <el-button v-hasPermi="['risk:relatedParties:remove']" type="text" icon="el-icon-delete" @click="delFamilyMembersHandle(scope.$index, scope.row)" />
            </template>
          </el-table-column>
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addriskFamilyMembersList">{{ $t('添加') }}</el-button>
        </div>
      </div>
      <div style="margin-top: 15px">
        <!--本人及关系密切家庭成员一级市场对外投资情况（填写直接投资或间接投资企业情况）-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('本人及关系密切家庭成员一级市场对外投资情况（填写直接投资或间接投资企业情况）') }}</span>
        </div>
        <el-table :data="form.riskForeignInvestmentList" border class="nowrapTable formTable">
          <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('投资人姓名')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('投资人姓名') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.investorName'" :rules="riskForeignInvestmentListRules.investorName">
                <el-select v-model="scope.row.investorName">
                  <el-option
                    v-for="item in nameOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('投资企业名称')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('投资企业名称') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.investEnterpriseName'" :rules="riskForeignInvestmentListRules.investEnterpriseName">
                <el-input v-model="scope.row.investEnterpriseName" :placeholder="$t('投资企业名称')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('注册资本') + $t('金额单位')" show-overflow-tooltip min-width="150">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('注册资本') }}{{ $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.registerCapital'" :rules="riskForeignInvestmentListRules.registerCapital">
                <Money v-model="scope.row.registerCapital" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('出资金额') + $t('金额单位')" show-overflow-tooltip min-width="150">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('出资金额') }}{{ $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.contributionAmount'" :rules="riskForeignInvestmentListRules.contributionAmount">
                <Money v-model="scope.row.contributionAmount" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('是否为实际控制人')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('是否为实际控制人') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.actualController'" :rules="riskForeignInvestmentListRules.actualController">
                <el-select v-model="scope.row.actualController">
                  <el-option
                    v-for="dict in actualControllerOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('投资类别')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('投资类别') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.investmentCategory'" :rules="riskForeignInvestmentListRules.investmentCategory">
                <el-select v-model="scope.row.investmentCategory">
                  <el-option
                    v-for="dict in investmentCategoryOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('对外投资起始日')" align="center" show-overflow-tooltip min-width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.foreignStartDate'">
                <DatePicker v-model="scope.row.foreignStartDate" :placeholder="$t('对外投资起始日')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('对外投资终止日')" align="center" show-overflow-tooltip min-width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.foreignEndDate'">
                <DatePicker v-model="scope.row.foreignEndDate" :placeholder="$t('对外投资终止日')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('备注')" align="center" show-overflow-tooltip min-width="180">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('备注') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskForeignInvestmentList.' + scope.$index + '.remark'">
                <el-input v-model="scope.row.remark" type="textarea" class="fileTextarea" maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" min-width="60px">
            <template slot-scope="scope">
              <el-button v-hasPermi="['risk:relatedParties:remove']" type="text" icon="el-icon-delete" @click="delForeignInvestmentHandle(scope.$index, scope.row)" />
            </template>
          </el-table-column>
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addForeignInvestmentList">{{ $t('添加') }}</el-button>
        </div>
      </div>
      <div style="margin-top: 15px">
        <!--本人及关系密切家庭成员担任董事、监事、高级管理人员、执行事务合伙人委派代表、投资决策机构委员企业基本情况-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('本人及关系密切家庭成员担任董事、监事、高级管理人员、执行事务合伙人委派代表、投资决策机构委员企业基本情况') }}</span>
        </div>
        <el-table :data="form.riskPostInfoList" border class="nowrapTable formTable">
          <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('投资人姓名')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('投资人姓名') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.investorName'" :rules="riskPostInfoListRules.investorName">
                <el-select v-model="scope.row.investorName">
                  <el-option
                    v-for="item in nameOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('任职企业')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('任职企业') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.workEnterprise'" :rules="riskPostInfoListRules.workEnterprise">
                <el-input v-model="scope.row.workEnterprise" :placeholder="$t('任职企业')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('担任职务')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('担任职务') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.position'" :rules="riskPostInfoListRules.position">
                <el-input v-model="scope.row.position" :placeholder="$t('担任职务')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('任期')" align="center" show-overflow-tooltip min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('任期') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.term'" :rules="riskPostInfoListRules.term">
                <el-input v-model="scope.row.term" :placeholder="$t('任期')" show-word-limit maxlength="30" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('任期起始日')" align="center" show-overflow-tooltip min-width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.termStartDate'">
                <DatePicker v-model="scope.row.termStartDate" :placeholder="$t('任期起始日')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('任期终止日')" align="center" show-overflow-tooltip min-width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.termEndDate'">
                <DatePicker v-model="scope.row.termEndDate" :placeholder="$t('任期终止日')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('备注')" align="center" show-overflow-tooltip min-width="180">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('备注') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'riskPostInfoList.' + scope.$index + '.remark'">
                <el-input v-model="scope.row.remark" type="textarea" class="fileTextarea" maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" min-width="60px">
            <template slot-scope="scope">
              <el-button v-hasPermi="['risk:relatedParties:remove']" type="text" icon="el-icon-delete" @click="delPostInfoHandle(scope.$index, scope.row)" />
            </template>
          </el-table-column>
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addPostInfoList">{{ $t('添加') }}</el-button>
        </div>
      </div>
      <!--   放在表单最后    -->
      <div style="margin-top: 15px">
        <el-col :span="24">
          <el-form-item prop="oneselfSure">
            <template>
              <el-checkbox :key="true" v-model="form.oneselfSure">{{ $t('本人确认上述登记内容真实、准确、完整，不存在任何虚假记载、误导性陈述或者重大遗漏。') }}</el-checkbox>
            </template>
          </el-form-item>
        </el-col>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="risk:relatedParties" />
    </div>
  </div>
</template>

<script>
import {
  saveRiskRelatedParties,
  getRiskRelatedParties,
  checkStaffName
} from '@/api/deal/risk/relatedParties/riskRelatedParties'
    import { getUser } from '@/api/system/user'
    import { listPost } from '@/api/system/post'
    import { treeselect } from '@/api/system/dept'
    import TreeSelect from '@/components/TreeSelect/index'
    import { delRiskFamilyMembers } from '@/api/deal/risk/familyMembers/riskFamilyMembers'
    import { delRiskForeignInvestment } from '@/api/deal/risk/foreignInvestment/riskForeignInvestment'
    import { delRiskPostInfo } from '@/api/deal/risk/postInfo/riskPostInfo'
    export default {
      components: {
        TreeSelect
      },
        data() {
            return {
                // 表单参数
                form: {
                  riskFamilyMembersList: [],
                  riskForeignInvestmentList: [],
                  riskPostInfoList: []
                },
                // 遮罩层
                loading: false,
                // 是否隐藏其它按钮
                otherBtnHide: false,
                // 关联方登记表单中的员工姓名
                currentStaffName: '',
                // 部门
                deptOptions: [],
                // 投资人姓名
                nameOptions: [],
                // 职位
                hrPositions: [],
                // 与本人关系
                relationshipOptions: [],
                // 是否为实际控制人
                actualControllerOptions: [],
                // 投资类别
                investmentCategoryOptions: [],
                // 表单校验
                rules: {
                  staffName: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }, { validator: this.checkStaffName, trigger: 'blur' }],
                  departmentId: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  idCard: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  oneselfSure: [{ required: true, message: this.$t('必填信息'),	trigger: ['blur', 'change'] }, { validator: this.checkOneselfSure, trigger: 'blur' }]
                },
                // 关系密切家庭成员基本情况表单校验
                riskFamilyMembersListRules: {
                  name: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  relationship: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  idCard: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
                // 本人及关系密切家庭成员一级市场对外投资情况表单校验
                riskForeignInvestmentListRules: {
                  investorName: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  investEnterpriseName: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  registerCapital: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  contributionAmount: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  actualController: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  investmentCategory: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
                // 本人及关系密切家庭成员担任董事、监事、高级管理人员、执行事务合伙人委派代表、投资决策机构委员企业基本情况表单校验
                riskPostInfoListRules: {
                  investorName: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  workEnterprise: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  position: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  term: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                }
            }
        },
        watch: {
          'form.staffName': {
            handler(val) {
              if (val !== undefined && val !== null && val !== '') { this.userInfo(val) }
            },
            deep: true,
            immediate: true
          },
          'form.riskFamilyMembersList': {
            handler() {
              if (this.form.riskFamilyMembersList !== []) {
                this.updateNameOption()
              }
            },
            deep: true,
            immediate: true
          }
        },
        created() {
          // 与本人关系
          this.getDicts('relation_ship').then(response => {
            this.relationshipOptions = response.data
          })
          // 是否为实际控制人
          this.getDicts('sys_yes_no').then(response => {
            this.actualControllerOptions = response.data
          })
          // 投资类别
          this.getDicts('investment_category').then(response => {
            this.investmentCategoryOptions = response.data
          })
          // 部门
          treeselect().then(response => {
            this.deptOptions = response.data
          })
          // 职位
          listPost({}).then(response => {
            this.hrPositions = response.rows
          })
        },
        methods: {
            // 初始化数据
            init(data) {
              this.loading = true
                if (data != null && data.id !== undefined) {
                    getRiskRelatedParties(data.id).then(response => {
                        this.form = response.data
                        if (this.form.oneselfSure === 'true') {
                          this.form.oneselfSure = true
                        }
                        this.$set(this.form, 'postId', response.data.postId)
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.form.staffName = this.$store.state.user.userId
                    this.userInfo(this.form.staffName)
                  this.loading = false
                }
            },
            // 根据选择的用户不同显示部门和岗位
            userInfo(userId) {
              getUser(userId).then(response => {
                this.form.departmentId = response.data.deptId
                this.form.postId = response.datas.postIds[0]
                // 设置当前员工姓名
                this.currentStaffName = response.data.nickName
                this.updateNameOption()
              })
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    staffName: undefined,
                    departmentId: undefined,
                    postId: undefined,
                    idCard: undefined,
                    passportNumber: undefined,
                    oneselfSure: false,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined,
                    riskFamilyMembersList: [],
                    riskForeignInvestmentList: [],
                    riskPostInfoList: []
                }
                this.resetForm('form')
            },
          updateNameOption() {
            this.nameOptions = []
            // 首先获取当前的关联方登记的员工姓名
            this.addNameOptions(this.currentStaffName)
            this.form.riskFamilyMembersList.forEach(item => {
              this.addNameOptions(item.name)
            })
          },
          // 添加关系密切家庭成员基本情况
          addNameOptions(val) {
              const row = {
                value: val,
                label: val
              }
              if (!(this.form.nameOptions instanceof Array)) {
                this.nameOptions = []
              }
              this.$nextTick(() => {
                this.nameOptions.push(row)
              })
          },
          // 添加关系密切家庭成员基本情况
          addriskFamilyMembersList() {
              const row = {
                id: undefined,
                relatedPartiesId: '',
                name: '',
                relationship: '',
                idCard: '',
                passportNumber: '',
                remark: ''
              }
              if (!(this.form.riskFamilyMembersList instanceof Array)) {
                this.$set(this.form, 'riskFamilyMembersList', [])
              }
              this.$nextTick(() => {
                this.form.riskFamilyMembersList.push(row)
              })
          },
          // 删除关系密切家庭成员基本情况
          delFamilyMembersHandle(index, row) {
            // eslint-disable-next-line no-undef
            const id = row.id
            if (id !== undefined && id !== '' && id != null) {
              this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              })
                .then(function() {
                  return delRiskFamilyMembers(id)
                }).then(() => {
                this.form.riskFamilyMembersList.splice(index, 1)
                return this.msgSuccess(this.$t('删除成功'))
              })
                .catch(function() {})
            } else {
              this.form.riskFamilyMembersList.splice(index, 1)
            }
          },
          // 添加本人及关系密切家庭成员一级市场对外投资情况对象
          addForeignInvestmentList() {
              const row = {
                id: undefined,
                relatedPartiesId: '',
                investorName: '',
                investEnterpriseName: '',
                registerCapital: '',
                contributionAmount: '',
                actualController: '',
                investmentCategory: '',
                foreignStartDate: '',
                foreignEndDate: '',
                remark: ''
              }
              if (!(this.form.riskForeignInvestmentList instanceof Array)) {
                this.$set(this.form, 'riskForeignInvestmentList', [])
              }
              this.$nextTick(() => {
                this.form.riskForeignInvestmentList.push(row)
              })
          },
          // 删除本人及关系密切家庭成员一级市场对外投资情况对象
          delForeignInvestmentHandle(index, row) {
            // eslint-disable-next-line no-undef
            const id = row.id
            if (id !== undefined && id !== '' && id != null) {
              this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              })
                .then(function() {
                  return delRiskForeignInvestment(id)
                }).then(() => {
                this.form.riskForeignInvestmentList.splice(index, 1)
                return this.msgSuccess(this.$t('删除成功'))
              })
                .catch(function() {})
            } else {
              this.form.riskForeignInvestmentList.splice(index, 1)
            }
          },
          // 添加本人及关系密切家庭成员担任董事、监事、高级管理人员、执行事务合伙人委派代表、投资决策机构委员企业基本情况
          addPostInfoList() {
              const row = {
                id: undefined,
                relatedPartiesId: '',
                investorName: '',
                workEnterprise: '',
                position: '',
                term: '至今',
                termStartDate: '',
                termEndDate: '',
                remark: ''
              }
              if (!(this.form.riskPostInfoList instanceof Array)) {
                this.$set(this.form, 'riskPostInfoList', [])
              }
              this.$nextTick(() => {
                this.form.riskPostInfoList.push(row)
              })
          },
          // 删除本人及关系密切家庭成员担任董事、监事、高级管理人员、执行事务合伙人委派代表、投资决策机构委员企业基本情况
          delPostInfoHandle(index, row) {
            // eslint-disable-next-line no-undef
            const id = row.id
            if (id !== undefined && id !== '' && id != null) {
              this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              })
                .then(function() {
                  return delRiskPostInfo(id)
                }).then(() => {
                this.form.riskPostInfoList.splice(index, 1)
                return this.msgSuccess(this.$t('删除成功'))
              })
                .catch(function() {})
            } else {
              this.form.riskPostInfoList.splice(index, 1)
            }
          },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        console.log(this.form)
                        saveRiskRelatedParties(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           },
          // 校验oneselfSure是否勾选
          checkOneselfSure(rule, value, callback) {
            if (value) {
              callback()
            } else {
              callback(new Error(this.$t('必填信息')))
            }
          },
          // 同一个用户不能再次录入
          async checkStaffName(rule, value, callback) {
            var checkRes = await checkStaffName(this.form.staffName)
            if (checkRes) {
              callback()
            } else {
              callback(new Error(this.$t('该员工已存在，不能重复添加')))
            }
          }

        }

    }
</script>
